package com.flyway.execise.flyway_db;

import co.paralleluniverse.fibers.Fiber;
import co.paralleluniverse.strands.SuspendableRunnable;

import java.util.Random;
import java.util.concurrent.ExecutorService;

import static java.util.concurrent.Executors.*;

/**
 * @date 19-8-26
 * @auther jackliang
 * @description TODO
 */
public class FiberTest {

    private static void  caculate(){
        long  a = 3, b = 2;
        long abx = new Random().nextLong();

        boolean b1 = (a / b) > abx;
        double a3 = b1 ? Math.random()/(a+b) : b ;
        assert Boolean.toString(b1).length() > a3;
    }


    public static void main(String[] args) {
        long test1  =  System.currentTimeMillis();
        for(int i = 0 ; i < 9000000;i++){
            Fiber.toRunnable((SuspendableRunnable) () -> caculate());
        }
        long test2  =  System.currentTimeMillis();

        System.out.println(test2-test1+"\t===> fiber");

        ExecutorService executorService = newFixedThreadPool(100);

        long test11  =  System.currentTimeMillis();
        for(int i = 0 ; i < 9000000;i++){
           executorService.submit(() -> caculate());
//            new Thread(()->caculate());
        }
        long test22  =  System.currentTimeMillis();
        System.out.println(test22-test11+"\t===> thread");
    }
}
